//
//  MoreCore.m
//  HHNMobileCore
//
//  Created by huhmf on 16/2/29.
//  Copyright © 2016年 huhmf. All rights reserved.
//

#import "MoreCore.h"
#import "requestMoreItemApi.h"

#import <MJExtension.h>

@implementation MoreCore


-(void)requestMoreItemSuccBlock:(void (^)(MoreModel *))succBlock failBLock:(void (^)(NSString *))failBlock
{
    requestMoreItemApi *api=[[requestMoreItemApi alloc] init];
    
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSError *err;
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseJSONObject
                                                             options:NSJSONReadingMutableContainers
                                                               error:&err];
        if(err) {
            LogError(TMsgCenter, @"requestMoreItemApi,json to dict error：%@", err.localizedDescription);
            failBlock([NSString stringWithFormat:@"error：%@",err.localizedDescription]);
            return;
        }
        
        
        //HHLog(@"result:%@",[request.responseJSONObject mj_JSONString]);
        int codeVlue=[((NSNumber *)[dict valueForKey:@"code"]) intValue];
        if (codeVlue!=0) {
            failBlock(@"");return;
        }
        succBlock([self DictionaryToObject:dict]);
        
    } failure:^(YTKBaseRequest *request) {
        LogError(TMsgCenter, @"requestMoreItemApi error:%@", request.requestTask.error.localizedDescription);
        failBlock(request.requestTask.error.localizedDescription);
    }];
}

-(MoreModel *)DictionaryToObject:(NSDictionary *)dict
{
    if (dict==nil) {
        return nil;
    }
    
    [MoreModel mj_setupObjectClassInArray:^NSDictionary *{
        return @{
                 @"dataInfo" :[MoreItem class]
                 };
    }];
    
    MoreModel *model=[MoreModel mj_objectWithKeyValues:dict];
    
    
    return model;
}

@end
